/*
 * Copyright (C) 2012  Romain DUBOIS
 * 
 * This file is part of NeMoS - Network and Modular Software
 * 
 * NeMoS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * NeMoS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with NeMoS.  If not, see <http://www.gnu.org/licenses/>.
 */
package nemos.remote.socket;

import java.io.IOException;

import nemos.remote.rsa.message.IConnection;
import nemos.remote.rsa.message.IServer;

import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;

/**
 * ISocketService : The socket service.
 * 
 * <p>
 * Each successfull connection (server join or creation with local flag)
 * registers also a {@link RemoteServiceAdmin} service.
 * </p>
 * 
 * @author Romain DUBOIS
 */
public interface ISocketService {

    /**
     * Create a socket server in local framework.
     * 
     * @param pPort
     *            The port to bound the server to
     * @return The created server (which is also registered as a service)
     * @throws IOException
     *             If server start failed
     */
    IServer createServer(int pPort) throws IOException;

    /**
     * Create a socket server in local framework.
     * 
     * @param pHostName
     *            The host name to use
     * @param pPort
     *            The port to bound the server to
     * @return The created server (which is also registered as a service)
     * @throws IOException
     *             If server start failed
     */
    IServer createServer(String pHostName, int pPort) throws IOException;

    /**
     * Join a socket server and bind the local framework to it.
     * 
     * @param pHostName
     *            The server host name
     * @param pPort
     *            The server port
     * @return The connection (which is also registered as a service)
     * @throws IOException
     *             If server connection failed
     */
    IConnection connectServer(String pHostName, int pPort) throws IOException;
}
